package cn.crm.dao;

import cn.crm.pojo.BaseDict;
import cn.crm.pojo.Customer;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CustomerMapper {

    @Select("<script>" +
            "select * from customer " +
            "<where>" +
            "   <if test=\"cust_name!=null and cust_name!=''\" >and cust_name like concat('%',#{cust_name},'%')</if>" +
            "   <if test=\"cust_source!=null and cust_source!=''\" >and cust_source = #{cust_source}</if>" +
            "   <if test=\"cust_industry!=null and cust_industry!=''\" >and cust_industry = #{cust_industry}</if>" +
            "   <if test=\"cust_level!=null and cust_level!=''\" >and cust_level = #{cust_level}</if>" +
            "</where>" +
            "</script>")
    public List<Customer> find(@Param("cust_name") String cust_name,
                               @Param("cust_source") String cust_source,
                               @Param("cust_industry") String cust_industry,
                               @Param("cust_level") String cust_level);


    @Select("SELECT * FROM base_dict WHERE dict_type_code=#{dict_type_code}")
    public List<BaseDict> list(@Param("dict_type_code") String dict_type_code);

    @Select("select * from customer where cust_id=#{cust_id}")
    public Customer findById(@Param("cust_id") Integer cust_id);

    @Insert("INSERT INTO customer " +
            "VALUES(null,#{cust_name},#{cust_user_id},#{cust_create_id},#{cust_source}," +
            "#{cust_industry},#{cust_level},#{cust_linkman},#{cust_phone}, " +
            "#{cust_mobile},#{cust_zipcode},#{cust_address},now())" )
    public int add(Customer customer);

    @Update("update customer " +
            "set cust_id=#{cust_id}," +
            "    cust_name=#{cust_name}," +
            "    cust_user_id=#{cust_user_id}," +
            "    cust_create_id=#{cust_create_id}," +
            "    cust_source=#{cust_source}," +
            "    cust_industry=#{cust_industry}," +
            "    cust_level=#{cust_level}," +
            "    cust_linkman=#{cust_linkman}," +
            "    cust_phone=#{cust_phone}, " +
            "    cust_mobile=#{cust_mobile}," +
            "    cust_zipcode=#{cust_zipcode}," +
            "    cust_address=#{cust_address} " +
            "where cust_id=#{cust_id}")
    public int update(Customer customer);

    @Delete("DELETE FROM customer where cust_id=#{cust_id}" )
    public int del(@Param("cust_id") Integer cust_id);
}
